package com.mdc.mansion.web.modules.pay.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.mdc.mansion.web.modules.system.utils.UserUtils;
import com.mdc.mansion.dataaccess.modules.system.entity.User;

import com.mdc.mansion.dataaccess.common.persistence.Page;
import com.mdc.mansion.dataaccess.modules.pay.entity.RestaurantOrderRefundBack;
import com.mdc.mansion.core.modules.pay.RestaurantOrderRefundBackService;
import com.mdc.mansion.web.common.web.BaseController;
/**
 * 菜品接收设置Controller
 * @author xizf
 * @version 2018-08-15
 */
@Controller
@RequestMapping(value = "${adminPath}/pay/restaurantOrderRefundBack")
public class RestaurantOrderRefundBackController extends BaseController {

	@Autowired
	private RestaurantOrderRefundBackService restaurantOrderRefundBackService;
	
	@ModelAttribute
	public RestaurantOrderRefundBack get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return restaurantOrderRefundBackService.get(id);
		}else{
			return new RestaurantOrderRefundBack();
		}
	}
	
	@RequiresPermissions("pay:restaurantOrderRefundBack:view")
	@RequestMapping(value = {"list", ""})
	public ModelAndView list(RestaurantOrderRefundBack restaurantOrderRefundBack) {
		Map<String, Object> model=new HashMap<String, Object>();
		Page<RestaurantOrderRefundBack> page = restaurantOrderRefundBackService.findPage(restaurantOrderRefundBack);
        model.put("page", page);
		ModelAndView modelAndView=new ModelAndView("modules/pay/restaurantOrderRefundBackList", model);
		return modelAndView;
	}
	
	@RequiresPermissions("pay:restaurantOrderRefundBack:view")
	@RequestMapping(value = "form")
	public ModelAndView form(RestaurantOrderRefundBack restaurantOrderRefundBack) {
		Map<String, Object> model=new HashMap<String, Object>();
		model.put("restaurantOrderRefundBack", restaurantOrderRefundBack);
		return new ModelAndView("modules/pay/restaurantOrderRefundBackForm",model);
	}
	

	@RequiresPermissions("pay:restaurantOrderRefundBack:edit")
	@RequestMapping(value = "save")
	public ModelAndView save(RestaurantOrderRefundBack restaurantOrderRefundBack,RedirectAttributes redirectAttributes) {
		User u=UserUtils.getUser();
		restaurantOrderRefundBack.setUpdateBy(u);
		if (StringUtils.isNotBlank(restaurantOrderRefundBack.getId())){
			restaurantOrderRefundBackService.updateSelective(restaurantOrderRefundBack);
		}else{
			restaurantOrderRefundBack.setCreateBy(u);
			restaurantOrderRefundBackService.save(restaurantOrderRefundBack);
		}
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
	@RequiresPermissions("pay:restaurantOrderRefundBack:edit")
	@RequestMapping(value = "delete")
	public ModelAndView delete(RestaurantOrderRefundBack restaurantOrderRefundBack,RedirectAttributes redirectAttributes) {
		restaurantOrderRefundBackService.delete(restaurantOrderRefundBack);
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
}
